package bTree.LeetCode;

import java.util.ArrayList;
import java.util.List;

public class 分割字符串的方案数 {
    public int numWays(String s) {
        int length = s.length();
        int[] nums = new int[length + 1];
        for (int i = 0; i < length; i++) {
            if (s.charAt(i) == '1') {
                nums[i + 1] = nums[i] + 1;
            } else {
                nums[i + 1] = nums[i];
            }
        }
        if (nums[length] % 3 != 0) {
            return 0;
        }
        if (nums[length]==0){
            long l = (long) (length - 1) * (long) (length - 2) / 2;
            long l1 = l % 1_000_000_007;
            return (int) l1;
        }
        int oneOfThree=0;
        int twoOfThree=0;
        int i = nums[length] / 3;
        for (int num : nums) {
            if (num==i){
                oneOfThree++;
            }
            if (num==2*i){
               twoOfThree++;
            }
        }
        long res= (long) oneOfThree *twoOfThree;
        long l = res % 1_000_000_007;
        return (int)l;
    }
}